var dataSource = new Array();
//table的数据源
var table;   //table对象
dataSource = [];
var excelType=0;


var customerCode=getQueryString('customerCode');
console.log(customerCode)
inte();
function inte(){
  $.ajax({
        url: root.consignee.getConsigneeList,
        cache: false,  //禁用缓存
        type: "POST",
        dataType: 'json',
        async: false,
        data: {
            "pageNum":1,
            "pageSize":20,
            "customerCode": customerCode

        },
      success: function (data) {
          console.log(data)
          couponlist(data.result);
          $('.M-box3').pagination({
              pageCount: data.totalPage,
              jump: true,
              coping: true,
              prevContent: '上页',
              nextContent: '下页',
              callback: function (api) {
                  console.log(api)
                  $.ajax({
                      url: root.consignee.getConsigneeApplyByPage,
                      cache: false,  //禁用缓存
                      type: "POST",
                      dataType:'json',
                      async:false,
                      data: {
                          "pageNum":1,
                          "pageSize":20
                      },
                      success: function (result) {
                          console.log(result)
                          couponlist(result.result);
                      },
                      error: function (XMLHttpRequest, textStatus, errorThrown) {
                          alert(XMLHttpRequest);
                      }
                  });
              }
          });

      },
      error: function () {
          $.Huimodalalert('失败！',2000);
      }
  });
}

function couponlist(data){
    // var j = 0;
    console.log(data)
    dataSource.splice(0,dataSource.length);//清空数组
    $.each(data, function (i, field) {

            var rowData = new Array();
            rowData.push(field.consignee_name);
            rowData.push(field.consignee_telephone);
            rowData.push(field.consignee_fixedphone);
            rowData.push(field.consignee_idcard);
            rowData.push(field.consignee_status);
            rowData.push(field.idCardPath);//身份证图片正面
            rowData.push(field.idCardOtherPath); //身份证图片反面
            rowData.push(field.instructionsPath); //授权说明书图片

        dataSource.push(rowData);

    });

    initDataTable(dataSource);

    function initDataTable(dataSource) {

        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            // "order": false,
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": false,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        if(row[4]==10){
                            val='启用'
                        } else if(row[4]==20){
                            val='禁用'
                        }
                        return val;
                    },
                    "targets":4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val='';
                        if(row[4]==10){
                            val = '<div><img onclick="picShow(\'查看图片\',\'../../html/goods/picShow.html\',\''+row[5]+'\',\'500\',\'300\',\'110\')" width="30" height="30" id="idCardPath" src=" '+row[5]+' " ><img onclick="picShow(\'查看图片\',\'../../html/goods/picShow.html\',\''+row[6]+'\',\'500\',\'300\',\'110\')" width="30" height="30" id="idCardOtherPath" src=" '+row[6]+' "><img onclick="picShow(\'查看图片\',\'../../html/goods/picShow.html\',\''+row[7]+'\',\'500\',\'300\',\'110\')" width="30" height="30" id="instructionsPath" src="'+row[7]+'" ></div>';

                        }else if(row[4]==20){
                            val = '<div><img onclick="picShow(\'查看图片\',\'../../html/goods/picShow.html\',\''+row[5]+'\',\'500\',\'300\',\'110\')" width="30" height="30" id="idCardPath" src=" '+row[5]+' " ><img onclick="picShow(\'查看图片\',\'../../html/goods/picShow.html\',\''+row[6]+'\',\'500\',\'300\',\'110\')" width="30" height="30" id="idCardOtherPath" src=" '+row[6]+' " ><img onclick="picShow(\'查看图片\',\'../../html/goods/picShow.html\',\''+row[7]+'\',\'500\',\'300\',\'110\')" width="30" height="30" id="instructionsPath" src="'+row[7]+'" ></div>';
                        }

                        return val;
                    },
                    "targets":5
                }

            ]
        });

    };
}
function picShow(title, url, imgUrl) {
    window.event ? window.event.cancelBubble = true : e.stopPropagation();
    sessionStorage.setItem("imgUrl", imgUrl);
    layer_show(title, url, "800", "500");
}







